<?php
namespace app\admin\controller;
use think\Db;
use think\Session;
use think\Request;
use think\Jump;
use app\admin\model\device_status_log  as deviceonline;

class Index  extends Common
{
    public function add(){
        $log=new deviceonline;
        $uuu=$log->online('9');
        echo $uuu;
    }
    public function index()
    {
            $cmuser=SESSION::get('cmuser');
            $where['master']=$cmuser;
            $info=Db::name('admin')->where($where)->find();
            $power=explode('|', $info['power']);
            $this->view->assign('power', $power);
            $ini=is_super_master();
            $this->view->assign('ini', $ini);
            $this->view->assign('cmuser', $cmuser);
       		return $this->view->fetch();
    }

    public function welcome()
    {
        /*
        
        //收发总数
        $alldevice['log_count']=Db::name('device_status_log')->count();
        //在线设备
        $a=strtotime('now');
        $c=$website['out_time'];
        $alldevice['info']=array();
        $alldevice['count']=Db::name('device')->count();
        $alldevice['info']=Db::name('device')->select();
        $i=0;
        foreach ($alldevice['info'] as $k => $v) {
           $b=strtotime($v['last_time']);
           if($a-$b<$c){
                $i++;
           }
        }
        $alldevice['percent']=round(($i/$alldevice['count'])*100,1);
        $alldevice['percent']=$alldevice['percent'].'%';
        $alldevice['i']=$i;
        $alldevice['second']=$c;


        //设备类型
        $alldevice['dev_string']=Db::name('device_type')->count();

        //相片数量
        $alldevice['imgconunt']=Db::name('video_log')->count();



        //图表数据
        for ($i=1; $i < 11 ; $i++) { 
            $data2_day="'".date("Y-m-d",strtotime("-$i day"))."',".$data2_day;

            $day7['device_status']=1;
            $now=date('Y-m-d 00:00:00',strtotime("-$i day"));
            $to=date('Y-m-d 23:59:59',strtotime("-$i day"));
            $day7['status_time']=array(between,array($now,$to));
            $data2_7s=Db::name('device_status_log')->where($day7)->count();
            $data2_dayx=$data2_7s.",".$data2_dayx;

            $day7['device_status']=0;
            $now=date('Y-m-d 00:00:00',strtotime("-$i day"));
            $to=date('Y-m-d 23:59:59',strtotime("-$i day"));
            $day7['status_time']=array(between,array($now,$to));
            $data2_7s=Db::name('device_status_log')->where($day7)->count();
            $data2_dayj=$data2_7s.",".$data2_dayj;
        }
        $alldevice['data2_day']=$data2_day;
        $alldevice['data2_dayx']=$data2_dayx;
        $alldevice['data2_dayj']=$data2_dayj;



        //最近设备动作
        $device_act=Db::name('device_act_log')->limit(0,7)->order('id')->select();
        //dump($device_act);
        $alldevice['device_act']=$device_act;


        //最近上下线
        $device_status=Db::name('device_status_log')->limit(0,4)->order('id')->select();
        //dump($device_act);
        $alldevice['device_status']=$device_status;
        $info=array();
        foreach ($alldevice['device_status'] as $k => $v) {
            $info['device_id']=$v['device_id'];
            $device_name=Db::name("device")->where($info)->find();
            if($device_name){
                $alldevice['device_status'][$k]['real_name']=$device_name['real_name'];
            }else{
                $alldevice['device_status'][$k]['real_name']='未知设备ID:'.$v['device_id'];
            }
        }

        //dump($alldevice['device_status']);

        $this->view->assign('alldevice', $alldevice);

        */
       $website=website();
       $this->view->assign('website', $website);
        return $this->view->fetch();
    }


    public function loginout(Request $request)
    {
        Session::clear('think');
        return 1;
    }
}
